FROM alpine:3.11.3

LABEL maintainer="Sean Murphy <xumeng010@126.com>"

ENV APP_NAME Dockovpn
ENV APP_INSTALL_PATH /opt/${APP_NAME}
ENV APP_PERSIST_DIR /opt/${APP_NAME}_data

WORKDIR ${APP_INSTALL_PATH}

COPY scripts .
COPY config ./config
COPY VERSION ./config

RUN apk update
RUN apk add --no-cache openvpn easy-rsa bash netcat-openbsd zip dumb-init && \
    mkdir -p ${APP_PERSIST_DIR} && \
    cd ${APP_PERSIST_DIR} && \
    /usr/share/easy-rsa/easyrsa init-pki && \
    /usr/share/easy-rsa/easyrsa gen-dh && \
    # DH parameters of size 2048 created at /usr/share/easy-rsa/pki/dh.pem
    # Copy DH file
    cp pki/dh.pem /etc/openvpn && \
    # Copy FROM ./scripts/server/conf TO /etc/openvpn/server.conf in DockerFile
    cd ${APP_INSTALL_PATH} && \
    cp config/server.conf /etc/openvpn/server.conf && \
    cp config/radiusplugin.conf /etc/openvpn/radiusplugin.conf

RUN wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1a_beta1.tar.gz
RUN apk add --no-cache libgpg-error
RUN apk add --no-cache libgcrypt
RUN apk add --no-cache libgcrypt-dev
RUN apk add --no-cache build-base
RUN tar -zxvf radiusplugin_v2.1a_beta1.tar.gz && \
    cd radiusplugin_v2.1a_beta1 && make && \
    cp radiusplugin.so /opt/Dockovpn/

RUN cd ${APP_INSTALL_PATH}

# 设置时区为中国上海时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

EXPOSE 1194/udp
EXPOSE 8080/tcp

VOLUME [ "/opt/Dockovpn_data" ]

ENTRYPOINT [ "dumb-init", "./start.sh" ]
CMD [ "" ]